<?php

namespace App\Models\API;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'phone', 'password',
    ];

    /**
     * 附加数据
     *
     * @var array
     */
    protected $appends = ['activity_count', 'tweet_count'];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function getActivityCountAttribute()
    {
        $id = $this->id;
        return $this->activities()->where('user_id', $id)->count();
    }

    public function getTweetCountAttribute()
    {
        $id = $this->id;
        return $this->tweets()->where('user_id', $id)->count();
    }

    public function activities()
    {
        return $this->hasMany('App\Models\API\Activity');
    }

    public function tweets()
    {
        return $this->hasMany('App\Models\API\Tweet');
    }
}